home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Glider 3.14 / source / Glider parts ƒ / G-InitializeAll.p < prev    next >
Encoding:
Text File  |  1991-05-14  |  27.1 KB  |  643 lines  |  [TEXT/PJMM]

  1. unit InitializeAll;
  2.  
  3. interface
  4.     uses
  5.         Sound, GameUtilities, GliderMain;
  6.  
  7.     procedure DoFast;
  8.     procedure Init_My_Menus;
  9.     function NewBitMap (var theBitMap: BitMap; theRect: Rect): ptr;
  10.     procedure InitAllRooms;
  11.     procedure InitAllVariables (prefs: Str255);
  12.  
  13.     var
  14.         AppleMenu: MenuHandle;            {Used to handle DAs, needed for later use}
  15.  
  16. implementation
  17.  
  18. {==============================================}
  19.  
  20.     procedure DoFast;
  21.     begin
  22.         advanceRate := 1;
  23.         scoresChanged := TRUE;
  24.         gravity := gravityFast;                    {Use the global const gravityFast for the rate    }
  25.         ductGravity := ceilingFast;                {of descent (for copters and gliders).  The        }
  26.         ventLift := floorFast;                    {other constants here work in the same way.    }
  27.         if (gliderCraft) then                    {The glider/dart's thrust of course depends    }
  28.             begin                                    {not only on the speed of the game, but also on}
  29.                 thrust := gliderForwardFast;        {the type of craft.  Recall in the docs that the    }
  30.                 stall := gliderBackwardFast;        {glider has a 2:1 glide ratio both forward and    }
  31.             end                                        {backward while the dart has a 4:1 forward    }
  32.         else                                        {but a 1:1 backward.  Look at the global con-    }
  33.             begin                                    {stants to confirm this.  The rooms were        }
  34.                 thrust := dartForwardFast;            {designed for the glider's ratio, but the dart    }
  35.                 stall := dartBackwardFast;            {just adds a little variety to the game.            }
  36.             end;
  37.     end;
  38.  
  39. {=============================================}
  40.  
  41.     procedure Init_My_Menus;
  42.         const
  43.             Menu1 = 201;                        {Menu resource ID for the Apple menu    }
  44.             Menu2 = 202;                        {Menu resource ID for the Game menu    }
  45.             Menu3 = 203;                        {Menu resource ID for the Options menu}
  46.         var
  47.             tempMenu: MenuHandle;            {Throw away all other menu handles    }
  48.     begin
  49.         ClearMenuBar;                        {Clear any old menu bars                }
  50.         tempMenu := GetMenu(Menu1);    {Get the menu from the resource file        }
  51.         AddResMenu(tempMenu, 'DRVR');    {Add in DAs                                }
  52.         InsertMenu(tempMenu, 0);            {Insert this menu into the menu bar        }
  53.         AppleMenu := tempMenu;            {Save this menu handle for later use    }
  54.         tempMenu := GetMenu(Menu2);    {Get the menu from the resource file        }
  55.         InsertMenu(tempMenu, 0);            {Insert this menu into the menu bar        }
  56.         tempMenu := GetMenu(Menu3);    {Get the menu from the resource file        }
  57.         InsertMenu(tempMenu, 0);            {Insert this menu into the menu bar        }
  58.         DrawMenuBar;                        {Draw the menu bar to reflect changes    }
  59.     end;
  60.  
  61. {=============================================}
  62.  
  63.     function NewBitMap;                {I pulled this routine stright from the pages of MacTutor    }
  64.     begin                                {Magazine.  I suggest you just grab the whole thing from    }
  65.         with theBitMap, theRect do    {here and pop it right into any program where you need    }
  66.             begin                            {off-screen bitmapping.  Note how it is called below.        }
  67.                 rowBytes := ((right - left + 15) div 16) * 2;        {calculates number of row bytes    }
  68.                 baseAddr := NewPtr(rowBytes * (bottom - top));    {defines base address for bitmap}
  69.                 bounds := theRect;                                        {define the .bounds field of map    }
  70.                 if (MemError <> noErr) then                            {do we have enough memory?    }
  71.                     begin
  72.                         SysBeep(1);                {Let's really yell at them.  Upgrade!  Upgrade me!            }
  73.                         SysBeep(1);
  74.                         NewBitMap := nil        {Set that pointer to zero-land.    }
  75.                     end
  76.                 else
  77.                     NewBitMap := baseAddr;    {So, we have enough memory!    }
  78.             end;
  79.     end;
  80.  
  81. {=============================================}
  82.  
  83.     procedure InitAllRooms;
  84.     begin
  85. {Here is the rather boring and tedious part.  This array holds all the data for each room.        }
  86. {It's fairly encrypted (unintentionally), but I'll try to give you the low-down.  Note that        }
  87. {levelArray is a 3-dimensional array.  Okay.  Anyway, the second dimension of the array        }
  88. {is only a little bit more complex.  The "zero-eth" cell of the 2nd-dimen. specifies the            }
  89. {number of "objects" in the room.  It acts as a sort of header value to tell SetupTheFurniture    }
  90. { how many times to loop through.}
  91.  
  92.         levelArray[1, 0, 1] := 4;        {Here's data for room #1.  Note here that        }
  93.         levelArray[1, 1, 1] := 4;        {will be 4 objects in this room. ([1,0,1] := 4)    }
  94.         levelArray[1, 1, 2] := 15;        {Now, after the "zero-eth" cell, the following    }
  95.         levelArray[1, 1, 3] := 200;    {cells in the 2nd-dim. specify what kind of        }
  96.         levelArray[1, 2, 1] := 2;        {object.  The 2nd object in this room happens    }
  97.         levelArray[1, 2, 2] := 112;    {to be a floor vent.  How do I know?  Because    }
  98.         levelArray[1, 2, 3] := 20;        {levelArray[1,2,1] := 2, and 2=floorvent.        }
  99.         levelArray[1, 3, 1] := 10;        {for a complete table of these "codes" look at    }
  100.         levelArray[1, 3, 2] := 200;    {SetUpTheFurniture; it is essentially one big    }
  101.         levelArray[1, 3, 3] := 140;    {case statement that extracts all it's info        }
  102.         levelArray[1, 3, 4] := 350;    {from this array.  Well, let's look at the floor    }
  103.         levelArray[1, 4, 1] := 2;        {vent [2, 1, 1] := 2 in the next room for a        }
  104.         levelArray[1, 4, 2] := 460;    {further example of what all is in this array.    }
  105.         levelArray[1, 4, 3] := 20;
  106.  
  107.         levelArray[2, 0, 1] := 4;        {Here we are with room 2's data.  Note here    }
  108.         levelArray[2, 1, 1] := 2;        {object 1 is a floor vent, but 2 more lines of    }
  109.         levelArray[2, 1, 2] := 250;    {data follow for the floor vent (namely, they    }
  110.         levelArray[2, 1, 3] := 20;        {are [2, 1, 2 ]:=250 & [2, 1, 3 ]:=20).  Well    }
  111.         levelArray[2, 2, 1] := 10;        {for a floor vent, the 2nd cell in the 3rd dim.    }
  112.         levelArray[2, 2, 2] := 61;        {specifies the horizontal position on the floor    }
  113.         levelArray[2, 2, 3] := 210;    {for this floor vent (all have the same vertical}
  114.         levelArray[2, 2, 4] := 201;    {position.  The 3rd cell in the 3rd dim. specif-    }
  115.         levelArray[2, 3, 1] := 10;        {ies how many pixels down from the top of the    }
  116.         levelArray[2, 3, 2] := 301;    {screen the air is to terminate.  20 puts this    }
  117.         levelArray[2, 3, 3] := 180;    {vent's column of air right up to the ceiling.    }
  118.         levelArray[2, 3, 4] := 401;    {Some vents (namely those under shelves &    }
  119.         levelArray[2, 4, 1] := 2;        {tables) nay have shorter columns of air.        }
  120.         levelArray[2, 4, 2] := 460;
  121.         levelArray[2, 4, 3] := 20;
  122.  
  123.         levelArray[3, 0, 1] := 5;        {Well, that should help sort out this array.        }
  124.         levelArray[3, 1, 1] := 3;        {All other objects have a similar format.  It    }
  125.         levelArray[3, 1, 2] := 170;    {depends of course on how much info is needed    }
  126.         levelArray[3, 2, 1] := 2;        {to specify the object.  You can examine the    }
  127.         levelArray[3, 2, 2] := 20;        {SetupTheFurniture procedure to decipher the    }
  128.         levelArray[3, 2, 3] := 20;        {rest.  Good luck!                                    }
  129.         levelArray[3, 3, 1] := 2;
  130.         levelArray[3, 3, 2] := 170;
  131.         levelArray[3, 3, 3] := 20;
  132.         levelArray[3, 4, 1] := 10;
  133.         levelArray[3, 4, 2] := 300;
  134.         levelArray[3, 4, 3] := 130;
  135.         levelArray[3, 4, 4] := 450;
  136.         levelArray[3, 5, 1] := 2;
  137.         levelArray[3, 5, 2] := 460;
  138.         levelArray[3, 5, 3] := 20;
  139.  
  140.         levelArray[4, 0, 1] := 4;
  141.         levelArray[4, 1, 1] := 2;
  142.         levelArray[4, 1, 2] := 460;
  143.         levelArray[4, 1, 3] := 20;
  144.         levelArray[4, 2, 1] := 2;
  145.         levelArray[4, 2, 2] := 80;
  146.         levelArray[4, 2, 3] := 20;
  147.         levelArray[4, 3, 1] := 10;
  148.         levelArray[4, 3, 2] := 237;
  149.         levelArray[4, 3, 3] := 210;
  150.         levelArray[4, 3, 4] := 329;
  151.         levelArray[4, 4, 1] := 10;
  152.         levelArray[4, 4, 2] := 298;
  153.         levelArray[4, 4, 3] := 130;
  154.         levelArray[4, 4, 4] := 468;
  155.  
  156.         levelArray[5, 0, 1] := 5;
  157.         levelArray[5, 1, 1] := 2;
  158.         levelArray[5, 1, 2] := 460;
  159.         levelArray[5, 1, 3] := 20;
  160.         levelArray[5, 2, 1] := 10;
  161.         levelArray[5, 2, 2] := 202;
  162.         levelArray[5, 2, 3] := 140;
  163.         levelArray[5, 2, 4] := 280;
  164.         levelArray[5, 3, 1] := 2;
  165.         levelArray[5, 3, 2] := 130;
  166.         levelArray[5, 3, 3] := 20;
  167.         levelArray[5, 4, 1] := 10;
  168.         levelArray[5, 4, 2] := 390;
  169.         levelArray[5, 4, 3] := 150;
  170.         levelArray[5, 4, 4] := 448;
  171.         levelArray[5, 5, 1] := 6;
  172.         levelArray[5, 5, 2] := 420;
  173.         levelArray[5, 5, 3] := 150;
  174.  
  175.         levelArray[6, 0, 1] := 6;
  176.         levelArray[6, 1, 1] := 4;
  177.         levelArray[6, 1, 2] := 15;
  178.         levelArray[6, 1, 3] := 200;
  179.         levelArray[6, 2, 1] := 2;
  180.         levelArray[6, 2, 2] := 70;
  181.         levelArray[6, 2, 3] := 40;
  182.         levelArray[6, 3, 1] := 9;
  183.         levelArray[6, 3, 2] := 148;
  184.         levelArray[6, 3, 3] := 210;
  185.         levelArray[6, 3, 4] := 300;
  186.         levelArray[6, 4, 1] := 9;
  187.         levelArray[6, 4, 2] := 210;
  188.         levelArray[6, 4, 3] := 100;
  189.         levelArray[6, 4, 4] := 350;
  190.         levelArray[6, 5, 1] := 2;
  191.         levelArray[6, 5, 2] := 380;
  192.         levelArray[6, 5, 3] := 20;
  193.         levelArray[6, 6, 1] := 1;
  194.         levelArray[6, 6, 2] := 30;
  195.         levelArray[6, 6, 3] := 200;
  196.  
  197.         levelArray[7, 0, 1] := 5;
  198.         levelArray[7, 1, 1] := 3;
  199.         levelArray[7, 1, 2] := 200;
  200.         levelArray[7, 2, 1] := 2;
  201.         levelArray[7, 2, 2] := 20;
  202.         levelArray[7, 2, 3] := 140;
  203.         levelArray[7, 3, 1] := 2;
  204.         levelArray[7, 3, 2] := 200;
  205.         levelArray[7, 3, 3] := 20;
  206.         levelArray[7, 4, 1] := 9;
  207.         levelArray[7, 4, 2] := 70;
  208.         levelArray[7, 4, 3] := 100;
  209.         levelArray[7, 4, 4] := 180;
  210.         levelArray[7, 5, 1] := 9;
  211.         levelArray[7, 5, 2] := 270;
  212.         levelArray[7, 5, 3] := 140;
  213.         levelArray[7, 5, 4] := 380;
  214.  
  215.         levelArray[8, 0, 1] := 7;
  216.         levelArray[8, 1, 1] := 2;
  217.         levelArray[8, 1, 2] := 22;
  218.         levelArray[8, 1, 3] := 20;
  219.         levelArray[8, 2, 1] := 9;
  220.         levelArray[8, 2, 2] := 100;
  221.         levelArray[8, 2, 3] := 135;
  222.         levelArray[8, 2, 4] := 208;
  223.         levelArray[8, 3, 1] := 9;
  224.         levelArray[8, 3, 2] := 280;
  225.         levelArray[8, 3, 3] := 150;
  226.         levelArray[8, 3, 4] := 490;
  227.         levelArray[8, 4, 1] := 5;
  228.         levelArray[8, 4, 2] := 182;
  229.         levelArray[8, 4, 3] := 135;
  230.         levelArray[8, 5, 1] := 5;
  231.         levelArray[8, 5, 2] := 302;
  232.         levelArray[8, 5, 3] := 150;
  233.         levelArray[8, 6, 1] := 2;
  234.         levelArray[8, 6, 2] := 450;
  235.         levelArray[8, 6, 3] := 180;
  236.         levelArray[8, 7, 1] := 6;
  237.         levelArray[8, 7, 2] := 278;
  238.         levelArray[8, 7, 3] := 150;
  239.  
  240.         levelArray[9, 0, 1] := 6;
  241.         levelArray[9, 1, 1] := 2;
  242.         levelArray[9, 1, 2] := 170;
  243.         levelArray[9, 1, 3] := 20;
  244.         levelArray[9, 2, 1] := 9;
  245.         levelArray[9, 2, 2] := 280;
  246.         levelArray[9, 2, 3] := 130;
  247.         levelArray[9, 2, 4] := 400;
  248.         levelArray[9, 3, 1] := 9;
  249.         levelArray[9, 3, 2] := 280;
  250.         levelArray[9, 3, 3] := 230;
  251.         levelArray[9, 3, 4] := 400;
  252.         levelArray[9, 4, 1] := 10;
  253.         levelArray[9, 4, 2] := 400;
  254.         levelArray[9, 4, 3] := 170;
  255.         levelArray[9, 4, 4] := 498;
  256.         levelArray[9, 5, 1] := 5;
  257.         levelArray[9, 5, 2] := 285;
  258.         levelArray[9, 5, 3] := 130;
  259.         levelArray[9, 6, 1] := 7;
  260.         levelArray[9, 6, 2] := 340;
  261.         levelArray[9, 6, 3] := 230;
  262.  
  263.         levelArray[10, 0, 1] := 7;
  264.         levelArray[10, 1, 1] := 2;
  265.         levelArray[10, 1, 2] := 20;
  266.         levelArray[10, 1, 3] := 20;
  267.         levelArray[10, 2, 1] := 2;
  268.         levelArray[10, 2, 2] := 400;
  269.         levelArray[10, 2, 3] := 20;
  270.         levelArray[10, 3, 1] := 9;
  271.         levelArray[10, 3, 2] := 160;
  272.         levelArray[10, 3, 3] := 180;
  273.         levelArray[10, 3, 4] := 380;
  274.         levelArray[10, 4, 1] := 2;
  275.         levelArray[10, 4, 2] := 280;
  276.         levelArray[10, 4, 3] := 230;
  277.         levelArray[10, 5, 1] := 9;
  278.         levelArray[10, 5, 2] := 70;
  279.         levelArray[10, 5, 3] := 250;
  280.         levelArray[10, 5, 4] := 170;
  281.         levelArray[10, 6, 1] := 9;
  282.         levelArray[10, 6, 2] := 70;
  283.         levelArray[10, 6, 3] := 100;
  284.         levelArray[10, 6, 4] := 170;
  285.         levelArray[10, 7, 1] := 7;
  286.         levelArray[10, 7, 2] := 73;
  287.         levelArray[10, 7, 3] := 250;
  288.  
  289.         levelArray[11, 0, 1] := 5;
  290.         levelArray[11, 1, 1] := 10;
  291.         levelArray[11, 1, 2] := 190;
  292.         levelArray[11, 1, 3] := 120;
  293.         levelArray[11, 1, 4] := 308;
  294.         levelArray[11, 2, 1] := 2;
  295.         levelArray[11, 2, 2] := 130;
  296.         levelArray[11, 2, 3] := 20;
  297.         levelArray[11, 3, 1] := 10;
  298.         levelArray[11, 3, 2] := 390;
  299.         levelArray[11, 3, 3] := 150;
  300.         levelArray[11, 3, 4] := 448;
  301.         levelArray[11, 4, 1] := 2;
  302.         levelArray[11, 4, 2] := 460;
  303.         levelArray[11, 4, 3] := 20;
  304.         levelArray[11, 5, 1] := 8;
  305.         levelArray[11, 5, 2] := 260;
  306.         levelArray[11, 5, 3] := 170;
  307.  
  308.         levelArray[12, 0, 1] := 7;
  309.         levelArray[12, 1, 1] := 1;
  310.         levelArray[12, 1, 2] := 70;
  311.         levelArray[12, 1, 3] := 100;
  312.         levelArray[12, 2, 1] := 9;
  313.         levelArray[12, 2, 2] := 70;
  314.         levelArray[12, 2, 3] := 50;
  315.         levelArray[12, 2, 4] := 500;
  316.         levelArray[12, 3, 1] := 9;
  317.         levelArray[12, 3, 2] := 70;
  318.         levelArray[12, 3, 3] := 170;
  319.         levelArray[12, 3, 4] := 200;
  320.         levelArray[12, 4, 1] := 9;
  321.         levelArray[12, 4, 2] := 280;
  322.         levelArray[12, 4, 3] := 170;
  323.         levelArray[12, 4, 4] := 430;
  324.         levelArray[12, 5, 1] := 5;
  325.         levelArray[12, 5, 2] := 300;
  326.         levelArray[12, 5, 3] := 170;
  327.         levelArray[12, 6, 1] := 2;
  328.         levelArray[12, 6, 2] := 200;
  329.         levelArray[12, 6, 3] := 70;
  330.         levelArray[12, 7, 1] := 2;
  331.         levelArray[12, 7, 2] := 430;
  332.         levelArray[12, 7, 3] := 100;
  333.  
  334.         levelArray[13, 0, 1] := 6;
  335.         levelArray[13, 1, 1] := 2;
  336.         levelArray[13, 1, 2] := 460;
  337.         levelArray[13, 1, 3] := 20;
  338.         levelArray[13, 2, 1] := 2;
  339.         levelArray[13, 2, 2] := 40;
  340.         levelArray[13, 2, 3] := 20;
  341.         levelArray[13, 3, 1] := 10;
  342.         levelArray[13, 3, 2] := 237;
  343.         levelArray[13, 3, 3] := 210;
  344.         levelArray[13, 3, 4] := 329;
  345.         levelArray[13, 4, 1] := 10;
  346.         levelArray[13, 4, 2] := 298;
  347.         levelArray[13, 4, 3] := 130;
  348.         levelArray[13, 4, 4] := 468;
  349.         levelArray[13, 5, 1] := 6;
  350.         levelArray[13, 5, 2] := 305;
  351.         levelArray[13, 5, 3] := 130;
  352.         levelArray[13, 6, 1] := 11;
  353.         levelArray[13, 6, 2] := 230;
  354.         levelArray[13, 6, 3] := 170;
  355.  
  356.         levelArray[14, 0, 1] := 5;        {Note: the dripping ceiling isn't specified here.    }
  357.         levelArray[14, 1, 1] := 3;        {The program handles both the dripping ceiling &    }
  358.         levelArray[14, 1, 2] := 130;    {the cat seperately.  Also, note that ALL rooms    }
  359.         levelArray[14, 2, 1] := 10;    {have copters in them and so they are also dealt    }
  360.         levelArray[14, 2, 2] := 202;    {with within the program itself.                        }
  361.         levelArray[14, 2, 3] := 140;
  362.         levelArray[14, 2, 4] := 300;
  363.         levelArray[14, 3, 1] := 2;
  364.         levelArray[14, 3, 2] := 130;
  365.         levelArray[14, 3, 3] := 20;
  366.         levelArray[14, 4, 1] := 10;
  367.         levelArray[14, 4, 2] := 390;
  368.         levelArray[14, 4, 3] := 150;
  369.         levelArray[14, 4, 4] := 448;
  370.         levelArray[14, 5, 1] := 2;
  371.         levelArray[14, 5, 2] := 460;
  372.         levelArray[14, 5, 3] := 20;
  373.  
  374.         levelArray[15, 0, 1] := 2;
  375.         levelArray[15, 1, 1] := 2;
  376.         levelArray[15, 1, 2] := 250;
  377.         levelArray[15, 1, 3] := 100;
  378.         levelArray[15, 2, 1] := 2;
  379.         levelArray[15, 2, 2] := 40;
  380.         levelArray[15, 2, 3] := 20;
  381.  
  382.         backgroundArray[1] := 172;    {Here we set up an array to hold the ID        }
  383.         backgroundArray[2] := 168;    {numbers of all background PICTs in the    }
  384.         backgroundArray[3] := 170;    {resource fork.  In room 6, for example,    }
  385.         backgroundArray[4] := 171;    {we use the PICT with ID=68.                }
  386.         backgroundArray[5] := 169;    {In part, the backgrounds were chosen at    }
  387.         backgroundArray[6] := 168;    {random, but some backgrounds just will    }
  388.         backgroundArray[7] := 169;    {not work with the furniture arrangement    }
  389.         backgroundArray[8] := 168;    {in the room (a shelf mounted to a window).}
  390.         backgroundArray[9] := 169;    {Get ResEdit and look at these PICT's in the}
  391.         backgroundArray[10] := 169;    {Glider_3.RSRC portion of this code.        }
  392.         backgroundArray[11] := 169;
  393.         backgroundArray[12] := 168;
  394.         backgroundArray[13] := 171;
  395.         backgroundArray[14] := 173;
  396.         backgroundArray[15] := 174;
  397.     end;
  398.  
  399. {=============================================}
  400.  
  401.     procedure InitAllVariables;
  402.         var
  403.             tempRect: Rect;
  404.             tempChar: Char;
  405.             defaultString: Str255;
  406.             rawPointer: Ptr;
  407.             theSnd: Handle;
  408.             tempStringHand: StringHandle;
  409.             Pic_Handle: PicHandle;
  410.     begin
  411.         gliderCraft := TRUE;
  412.         DoFast;
  413.         levelBegin := defaultRoomBegin;    {Here we set up all other default values                 }
  414.         numberBegin := defaultNumber;
  415.         gliderNumber := numberBegin;
  416.         doneFlag := FALSE;                    {Here follows the Boolean vars and initial settings    }
  417.         Pausing := FALSE;
  418.         Playing := FALSE;
  419.         darkOn := FALSE;
  420.         soundPlaying := FALSE;
  421.         levelOn := 1;                            {And which room we begin in (by default)}
  422.         chanPtr := nil;
  423.         GetPort(oldPort);
  424.  
  425.         if (inhibitSound) then
  426.             begin
  427.                 SetItem(GetMenu(L_Options), C_Sound_On, 'No Sound : need ≥ Sys 6.02');
  428.                 DisableItem(GetMenu(L_Options), C_Sound_On);        {and disable it (changing the name is a public    }
  429.             end;
  430.  
  431.         if (gameSpeed = fastSpeed) then
  432.             begin
  433.                 CheckItem(GetMenu(L_Options), C_Fast, TRUE);    {If on, put a checkmark        }
  434.                 CheckItem(GetMenu(L_Options), C_Slow, FALSE);    {If on, put a checkmark        }
  435.             end
  436.         else
  437.             begin
  438.                 CheckItem(GetMenu(L_Options), C_Slow, TRUE);    {If on, put a checkmark        }
  439.                 CheckItem(GetMenu(L_Options), C_Fast, FALSE);    {If on, put a checkmark        }
  440.             end;
  441.  
  442.         rawPointer := NewPtr(SizeOf(GrafPort));                {This offscreen bitmap will be for forming    }
  443.         loadPort := GrafPtr(rawPointer);                        {all the composites before dumping to the    }
  444.         OpenPort(loadPort);                                        {screen.}
  445.         SetRect(loadArea, 0, 0, 512, 322);                    {Note: here is where we call the above        }
  446.         loadBits := NewBitMap(loadMap, loadArea);            {function NewBitMap.  Grab this code for    }
  447.         SetPortBits(loadMap);                                    {your own programs.  See the globals for    }
  448.         EraseRect(loadMap.bounds);                                {a the variable types.                        }
  449.  
  450.         rawPointer := NewPtr(SizeOf(GrafPort));                {Here we keep all the various objects we'll}
  451.         objectsPort := GrafPtr(rawPointer);                    {need during play.  Note that we load them    }
  452.         OpenPort(objectsPort);                                    {up from the resource fork here as well.    }
  453.         SetRect(objectsArea, 0, 0, 512, 320);
  454.         objectsBits := NewBitMap(objectsMap, objectsArea);
  455.         SetPortBits(objectsMap);
  456.         EraseRect(objectsMap.bounds);
  457.         SetPort(objectsPort);                                    {Set the off-screen as the active port!    }
  458.         Pic_Handle := GetPicture(200);                        {Get objects into memory (PICT ID=200)}
  459.         SetRect(tempRect, 0, 0, 512, 320);
  460.         if (Pic_Handle <> nil) then                            {Only use handle if it is valid                }
  461.             begin
  462.                 ClipRect(tempRect);
  463.                 HLock(Handle(Pic_Handle));                            {Lock the handle before using it            }
  464.                 tempRect.Right := tempRect.Left + (Pic_Handle^^.picFrame.Right - Pic_Handle^^.picFrame.Left);
  465.                 tempRect.Bottom := tempRect.Top + (Pic_Handle^^.picFrame.Bottom - Pic_Handle^^.picFrame.Top);
  466.                 HUnLock(Handle(Pic_Handle));                        {Unlock the picture again                    }
  467.                 DrawPicture(Pic_Handle, tempRect);                {Since we SetPort(objectsMap), the        }
  468.             end;                                                        {picture is drawn off-screen.                }
  469.         SetRect(tempRect, 0, 0, 1023, 1023);                {Widen the clip area again                    }
  470.         ClipRect(tempRect);                                        {Set the clip area                            }
  471.         ReleaseResource(Handle(Pic_Handle));                {This frees up memory since we're done}
  472.  
  473.         rawPointer := NewPtr(SizeOf(GrafPort));            {Here we keep a "virgin" copy of the    }
  474.         virginPort := GrafPtr(rawPointer);                    {room unspoilt by the animated objects.    }
  475.         OpenPort(virginPort);
  476.         SetRect(screenArea, 0, 0, 512, 322);
  477.         virginBits := NewBitMap(virginMap, screenArea);
  478.         SetPortBits(virginMap);
  479.         EraseRect(virginMap.bounds);
  480.  
  481.         SetPort(oldPort);
  482.  
  483.         SetRect(playerDropRect, startHori, startVert, startHori, startVert);
  484.         SetRect(shadowDropRect, startHori, shadowVert, startHori, shadowVert);
  485.         ResizeARect(playerDropRect, 0);
  486.         ResizeARect(shadowDropRect, 53);
  487.         oldPlayerRect := playerDropRect;
  488.         oldShadowRect := shadowDropRect;
  489.         SetRect(playArea, 30, 10, 510, 280);
  490. {Here follows the MOST tedious part of programming games like this.  The objectsRects    }
  491. {array is of primary importance to the drawing routines in the program.  All the objects    }
  492. {in all of the rooms is crammed into a single PICT with ID=200 in the resource fork (use    }
  493. {ResEdit to look at this mess).  We loaded this PICT into the objectsMap offscreen bitmap,    }
  494. {and we now need some bounding rects defined to give CopyBits and CopyMask info as to    }
  495. {where in objectsMap these silly drawings are to be found.  Well, objectsRects holds all    }
  496. {the info on the rectangular areas where the objects and their masks are to be found.        }
  497. {How to get these?  Well once you have your PICT completely drawn with masks in Mac-    }
  498. {Paint (or similar "bitmap editor" use Show Mouse Position or a DA that will suffice to    }
  499. {give you the pixel coordinates of the left, top, right & bottom sides of the bounding rect.    }
  500. {Note: add 1 onto both the bottom and right edges of the rect.  Show Mouse Position (on    }
  501. {MacPaint 2.0 anyway) seems to give you the coords for the upper left of each pixel.        }
  502.         SetRect(objectsRects[0, 0], 2, 1, 48, 19);                {Glider in forward position}
  503.         SetRect(objectsRects[0, 1], 2, 22, 48, 40);                {it's mask}
  504.         SetRect(objectsRects[1, 0], 48, 2, 96, 22);            {Glider in backward position}
  505.         SetRect(objectsRects[1, 1], 48, 23, 96, 43);                {it's mask}
  506.         SetRect(objectsRects[2, 0], 152, 1, 217, 23);        {Dart}
  507.         SetRect(objectsRects[2, 1], 152, 24, 217, 46);            {it's mask}
  508.         SetRect(objectsRects[3, 0], 389, 77, 405, 101);        {Wall socket}
  509.         SetRect(objectsRects[3, 1], 407, 77, 423, 101);            {it's mask}
  510.         SetRect(objectsRects[4, 0], 100, 83, 147, 96);        {Floor vent}
  511.         SetRect(objectsRects[4, 1], 100, 97, 147, 110);            {it's mask}
  512.         SetRect(objectsRects[5, 0], 100, 37, 148, 50);        {Ceiling suction vent}
  513.         SetRect(objectsRects[5, 1], 100, 67, 148, 80);            {it's mask}
  514.         SetRect(objectsRects[6, 0], 100, 53, 148, 66);        {Ceiling blower}
  515.         SetRect(objectsRects[6, 1], 100, 67, 148, 80);            {it's mask}
  516.         SetRect(objectsRects[7, 0], 31, 42, 62, 76);            {Candle number 1}
  517.         SetRect(objectsRects[7, 1], 32, 78, 62, 112);            {it's mask}
  518.         SetRect(objectsRects[8, 0], 2, 55, 29, 83);            {Clock}
  519.         SetRect(objectsRects[8, 1], 2, 84, 29, 112);                {it's mask}
  520.         SetRect(objectsRects[9, 0], 160, 61, 210, 82);        {Folded paper}
  521.         SetRect(objectsRects[9, 1], 160, 83, 210, 104);            {it's mask}
  522.         SetRect(objectsRects[10, 0], 425, 49, 440, 73);        {Thermostat}
  523.         SetRect(objectsRects[10, 1], 407, 77, 423, 101);        {it's mask}
  524.         SetRect(objectsRects[11, 0], 417, 2, 428, 21);        {Shelf bracket}
  525.         SetRect(objectsRects[11, 1], 417, 23, 428, 42);            {it's mask}
  526.         SetRect(objectsRects[12, 0], 336, 73, 383, 86);        {Table base object}
  527.         SetRect(objectsRects[12, 1], 336, 88, 383, 101);        {it's mask}
  528.         SetRect(objectsRects[13, 0], 425, 77, 440, 101);    {Light switch}
  529.         SetRect(objectsRects[13, 1], 407, 77, 423, 101);        {it's mask}
  530.         SetRect(objectsRects[14, 0], 31, 42, 62, 76);        {Candle number 2}
  531.         SetRect(objectsRects[14, 1], 66, 78, 97, 112);            {it's mask}
  532.         SetRect(objectsRects[15, 0], 220, 1, 253, 36);        {Helicopter 1}
  533.         SetRect(objectsRects[15, 1], 220, 36, 253, 71);            {it's mask}
  534.         SetRect(objectsRects[16, 0], 250, 1, 283, 36);        {Helicopter 2}
  535.         SetRect(objectsRects[16, 1], 336, 221, 369, 256);        {it's mask}
  536.         SetRect(objectsRects[17, 0], 269, 1, 302, 36);        {Helicopter 3}
  537.         SetRect(objectsRects[17, 1], 269, 36, 302, 71);            {it's mask}
  538.         SetRect(objectsRects[18, 0], 289, 1, 322, 36);        {Helicopter 4}
  539.         SetRect(objectsRects[18, 1], 336, 258, 369, 293);        {it's mask}
  540.         SetRect(objectsRects[19, 0], 318, 1, 351, 36);        {Helicopter 5}
  541.         SetRect(objectsRects[19, 1], 318, 36, 351, 71);            {it's mask}
  542.         SetRect(objectsRects[20, 0], 348, 1, 381, 36);        {Helicopter 6}
  543.         SetRect(objectsRects[20, 1], 336, 258, 369, 293);        {it's mask}
  544.         SetRect(objectsRects[21, 0], 367, 1, 400, 36);        {Helicopter 7}
  545.         SetRect(objectsRects[21, 1], 367, 36, 400, 71);            {it's mask}
  546.         SetRect(objectsRects[22, 0], 387, 1, 420, 36);        {Helicopter 8}
  547.         SetRect(objectsRects[22, 1], 336, 221, 369, 256);        {it's mask}
  548.         SetRect(objectsRects[23, 0], 221, 75, 245, 88);        {Water drop 1}
  549.         SetRect(objectsRects[23, 1], 221, 92, 245, 104);        {it's mask}
  550.         SetRect(objectsRects[24, 0], 246, 75, 270, 88);        {Water drop 2}
  551.         SetRect(objectsRects[24, 1], 246, 92, 270, 104);        {it's mask}
  552.         SetRect(objectsRects[25, 0], 271, 75, 296, 88);        {Water drop 3}
  553.         SetRect(objectsRects[25, 1], 271, 92, 296, 104);        {it's mask}
  554.         SetRect(objectsRects[26, 0], 297, 75, 322, 88);        {Water drop 4}
  555.         SetRect(objectsRects[26, 1], 297, 92, 322, 104);        {it's mask}
  556.         SetRect(objectsRects[27, 0], 325, 73, 334, 87);        {Falling water drop}
  557.         SetRect(objectsRects[27, 1], 325, 89, 334, 103);        {it's mask}
  558.         SetRect(objectsRects[28, 0], 3, 115, 106, 176);        {Cat1}
  559.         SetRect(objectsRects[28, 1], 211, 115, 314, 176);        {it's mask}
  560.         SetRect(objectsRects[29, 0], 107, 115, 210, 176);    {Cat2}
  561.         SetRect(objectsRects[29, 1], 315, 115, 418, 176);        {it's mask}
  562.         SetRect(objectsRects[30, 0], 2, 177, 34, 217);        {Cat paw 1}
  563.         SetRect(objectsRects[30, 1], 194, 177, 226, 217);        {it's mask}
  564.         SetRect(objectsRects[31, 0], 36, 177, 76, 217);        {Cat paw 2}
  565.         SetRect(objectsRects[31, 1], 228, 177, 268, 217);        {it's mask}
  566.         SetRect(objectsRects[32, 0], 78, 177, 132, 217);    {Cat paw 3}
  567.         SetRect(objectsRects[32, 1], 270, 177, 324, 217);        {it's mask}
  568.         SetRect(objectsRects[33, 0], 134, 177, 189, 217);    {Cat paw 4}
  569.         SetRect(objectsRects[33, 1], 326, 177, 381, 217);        {it's mask}
  570.         SetRect(objectsRects[34, 0], 3, 221, 321, 240);            {Banner}
  571.         SetRect(objectsRects[34, 1], 3, 241, 321, 260);                {it's mask}
  572.         SetRect(objectsRects[35, 0], 422, 124, 461, 143);        {Crunched glider}
  573.         SetRect(objectsRects[35, 1], 422, 162, 461, 181);            {it's mask}
  574.         SetRect(objectsRects[36, 0], 0, 0, 0, 0);    {unused}
  575.         SetRect(objectsRects[36, 1], 0, 0, 0, 0);    {unused}
  576.         SetRect(objectsRects[37, 0], 447, 33, 494, 67);            {Burning glider 1}
  577.         SetRect(objectsRects[37, 1], 447, 71, 494, 105);            {it's mask}
  578.         SetRect(objectsRects[38, 0], 462, 107, 509, 145);        {Burning glider 2}
  579.         SetRect(objectsRects[38, 1], 462, 145, 509, 183);            {it's mask}
  580.         SetRect(objectsRects[39, 0], 0, 0, 0, 0);    {unused}
  581.         SetRect(objectsRects[39, 1], 0, 0, 0, 0);    {unused}
  582.         SetRect(objectsRects[40, 0], 0, 0, 0, 0);    {unused}
  583.         SetRect(objectsRects[40, 1], 0, 0, 0, 0);    {unused}
  584.         SetRect(objectsRects[41, 0], 388, 242, 432, 276);    {Folding plane 1 - no masks    }
  585.         SetRect(objectsRects[42, 0], 388, 277, 432, 311);    {Folding plane 2 - we'll get    }
  586.         SetRect(objectsRects[43, 0], 433, 207, 477, 241);    {Folding plane 3 - get lazy &    }
  587.         SetRect(objectsRects[44, 0], 433, 242, 477, 276);    {Folding plane 4 - do these    on    }
  588.         SetRect(objectsRects[45, 0], 433, 277, 477, 311);    {Folding plane 5 - a white        }
  589.         SetRect(objectsRects[46, 0], 478, 187, 507, 221);    {Folding plane 6 - background.    }
  590.         SetRect(objectsRects[47, 0], 478, 222, 507, 240);    {Folding plane 7}
  591.         SetRect(objectsRects[48, 0], 478, 241, 507, 265);    {Folding plane 8}
  592.         SetRect(objectsRects[49, 0], 478, 266, 507, 279);    {Folding plane 9}
  593.         SetRect(objectsRects[50, 0], 478, 280, 507, 294);    {Folding plane 10}
  594.         SetRect(objectsRects[51, 0], 478, 295, 507, 303);    {Folding plane 11}
  595.         SetRect(objectsRects[52, 0], 478, 304, 507, 315);    {Folding plane 12}
  596.         SetRect(objectsRects[53, 0], 97, 3, 138, 16);        {Glider shadow}
  597.         SetRect(objectsRects[53, 1], 97, 3, 138, 16);            {it's mask}
  598.         SetRect(objectsRects[54, 0], 154, 48, 216, 58);        {Dart shadow}
  599.         SetRect(objectsRects[54, 1], 154, 48, 216, 58);            {it's mask}
  600.         SetRect(objectsRects[55, 0], 265, 294, 323, 320);    {Crushed dart}
  601.         SetRect(objectsRects[55, 1], 324, 294, 381, 320);        {it's mask}
  602.         SetRect(objectsRects[56, 0], 1, 289, 66, 320);        {Burning dart 1}
  603.         SetRect(objectsRects[56, 1], 68, 289, 133, 320);        {it's mask}
  604.         SetRect(objectsRects[57, 0], 135, 286, 199, 320);    {Burning dart 2}
  605.         SetRect(objectsRects[57, 1], 200, 286, 264, 320);        {it's mask}
  606.  
  607.         SetRect(catBodyRect, 283, 165, 386, 226);        {"Special" rectangles.    }
  608.         pawRect := objectsRects[30, 0];
  609.         OffsetRect(pawRect, 281, -16);
  610.         oldPawRect := pawRect;
  611.         SetRect(dangerRect, 258, 145, 303, 200);
  612.         escapeRect := dangerRect;
  613.         InsetRect(escapeRect, 6, 6);
  614.  
  615.         theSnd := GetNamedResource('snd ', 'bonus.snd');        {Finally, we preload all the sounds    }
  616.         MoveHHi(theSnd);                                            {in from the resource fork so that    }
  617.         ReleaseResource(theSnd);
  618.         theSnd := GetNamedResource('snd ', 'ductsuck.snd');    {we don't have a dreaded pause as    }
  619.         MoveHHi(theSnd);                                            {each sound is needed.                    }
  620.         ReleaseResource(theSnd);
  621.         theSnd := GetNamedResource('snd ', 'ductdump.snd');
  622.         MoveHHi(theSnd);
  623.         ReleaseResource(theSnd);
  624.         theSnd := GetNamedResource('snd ', 'crunch.snd');
  625.         MoveHHi(theSnd);
  626.         ReleaseResource(theSnd);
  627.         theSnd := GetNamedResource('snd ', 'boom.snd');
  628.         MoveHHi(theSnd);
  629.         ReleaseResource(theSnd);
  630.         theSnd := GetNamedResource('snd ', 'drip.snd');
  631.         MoveHHi(theSnd);
  632.         ReleaseResource(theSnd);
  633.         theSnd := GetNamedResource('snd ', 'fold.snd');
  634.         MoveHHi(theSnd);
  635.         ReleaseResource(theSnd);
  636.         theSnd := GetNamedResource('snd ', 'flash.snd');
  637.         MoveHHi(theSnd);
  638.         ReleaseResource(theSnd);
  639.     end;
  640.  
  641. {=============================================}
  642.  
  643. end.